/**
	License:		Artistic license 2.0 (see license.txt, also available online at http://www.perlfoundation.org/artistic_license_2_0)
	Authors:		OrbitalLab (http://www.orbitallab.ru/moonglide/), 2007-2009

	File:			ShaderIO.d
	Description:	shader loading
	Date:			6.12.2007 by Jurec
*/
module moonglide.resources.io.shader.ShaderIO;

import
	tango.io.stream.Lines,
	moonglide.resources.io.IResIOProvider;

// /////////

static this()
{
	CShaderIOProvider shprov = new CShaderIOProvider;

	CResManager().RegisterProvider( shprov );
}

//================================================================
/// shader io provider class
//================================================================
class CShaderIOProvider : IResIOProvider
{
	public:
		void Load( char[] extension, ref IResource res, InputStream stream, uint streamsize )
		in
		{
			moonAssert( res !is null, "res is null", __FILE__, __LINE__ );
			moonAssert( streamsize > 0, "streamsize is 0", __FILE__, __LINE__ );
			moonAssert( stream !is null, "stream is null", __FILE__, __LINE__ );
			moonAssert( res.classinfo.name == CResShader.classinfo.name,
				"trying to load " ~ res.classinfo.name ~ " as CResShader", __FILE__, __LINE__ );
		}
		body
		{
			auto resCasted = cast(CResShader)res;

			foreach( line; new Lines!(char)(stream) )
				resCasted.text ~= line;
		}

		bool Save( char[] format, IResource res, ref Array buf ) { return false; }

		void CreateErrorResourceData( IResource res, char[] errorResName )
		{
			// TODO: implement!
		}

		char[] GetResourceClass() { return CResShader.classinfo.name; }
}
